﻿using Basic.FlowDAL;
using Basic.FlowModel.DB;
using Basic.FlowRemoteModel.AuditSignFile.Model;
using WeDonekRpc.Helper;

namespace Basic.FlowCollect.lmpl
{
    internal class FlowAuditSignFileCollect : IFlowAuditSignFileCollect
    {
        private readonly IFlowAuditSignFileDAL _BasicDAL;

        public FlowAuditSignFileCollect ( IFlowAuditSignFileDAL basicDAL )
        {
            this._BasicDAL = basicDAL;
        }
        public long Add ( AuditSignFileAdd add )
        {
            if ( this._BasicDAL.IsExists(c => c.LogId == add.LogId && c.FormFileId == add.FormFileId) )
            {
                throw new ErrorException("flow.audit.sign.file.repeat");
            }
            return this._BasicDAL.Add(add);
        }
        public bool SetImgUri ( DBFlowAuditSignFile file, string imgUri )
        {
            if ( file.ImgUri == imgUri )
            {
                return false;
            }
            this._BasicDAL.SetImgUri(file.Id, imgUri);
            return true;
        }
        public DBFlowAuditSignFile Get ( long id )
        {
            return this._BasicDAL.Get(id);
        }
        public Result Get<Result> ( long id ) where Result : class, new()
        {
            return this._BasicDAL.Get<Result>(id);
        }
        public void Delete ( DBFlowAuditSignFile obj )
        {
            this._BasicDAL.Delete(obj.Id);
        }
        public Result[] Gets<Result> ( long logId ) where Result : class, new()
        {
            return this._BasicDAL.Gets<Result>(c => c.LogId == logId);
        }
    }
}
